#include "qs_config.h"
#include "qs_crc8.h"



unsigned char CRC8Calculate(void *pBuf ,unsigned pBufSize)  
{  
    unsigned char retCRCValue=0x00;  
    unsigned char *pData;  
    int i=0;  
    unsigned char pDataBuf=0;  
  //  retCRCValue=0x01;  
    pData=(unsigned char *)pBuf;  
   // pDataBuf=pData[0];  
   // cout<<hex<<pDataBuf<<endl;  
  
     while(pBufSize--)  
     {  
         pDataBuf=*pData++;  
         for(i=0;i<8;i++)  
         {  
             if((retCRCValue^(pDataBuf))&0x01)  
             {  
                 retCRCValue^=0x18;  
                 retCRCValue>>=1;  
                 retCRCValue|=0x80;  
             //    printf("i=%d;retCRCValue=%x\n",i,retCRCValue);  
             }  
             else  
             {  
                   retCRCValue>>=1;  
             //     printf("i=%d;retCRCValue=%x\n",i,retCRCValue);  
             }  
            pDataBuf>>=1;  
         }  
     }  
     return retCRCValue;  
}  
